using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.Shell.Interop;
using Koda.Search;
using EnvDTE80;

namespace Koda.Search.Finders
{
    public class TypeFinder : SymbolFinderBase
    {
        protected override _LIB_LISTTYPE ListType
        {
            get
            {
                return _LIB_LISTTYPE.LLT_CLASSES;
            }
        }

        protected override LIB_CATEGORY Category
        {
            get
            {
                return LIB_CATEGORY.LC_CLASSTYPE;
            }
        }

        public TypeFinder(DTE2 dte)
            : base(dte)
        {
        }

        protected override VsItemType GetVsItemType(uint value)
        {
            switch ((_LIBCAT_CLASSTYPE)value)
            {
                case _LIBCAT_CLASSTYPE.LCCT_CLASS:
                    return VsItemType.Class;

                case _LIBCAT_CLASSTYPE.LCCT_INTERFACE:
                    return VsItemType.Interface;

                case _LIBCAT_CLASSTYPE.LCCT_ENUM:
                    return VsItemType.Enum;

                case _LIBCAT_CLASSTYPE.LCCT_DELEGATE:
                    return VsItemType.Delegate;

                case _LIBCAT_CLASSTYPE.LCCT_STRUCT:
                    return VsItemType.Structure;

                default:
                    return VsItemType.Unknown;
            }
        }

        protected override string ParseName(string fullName)
        {
            int position = fullName.LastIndexOf('.');
            if (position > -1 && (position + 1) < fullName.Length)
                return fullName.Substring(position + 1);
            return fullName;
        }
    }
}
